package com.king.armips;

import java.util.ArrayList;
import java.util.List;

public class ArgumentsParseException extends Exception{
    private final int code;
    private String[] args;

    //"Arguments string is null"
    public static final int ERROR_NULL_ARGUMENTS = -1;
    //"Missing argument for \"-temp\""
    public static final int ERROR_MISSING_ARGUMENT_TEMP = -2;
    //"Missing arguments for \"-equ\"";
    public static final int ERROR_MISSING_ARGUMENTS_EQU = -3;
    //"Invalid equation name \"" + name + "\"";
    public static final int ERROR_INVALID_EQUATION_NAME = -4;
    //"\"-time\" flag is deprecated";
    public static final int ERROR_DEPRECATED_TIME = -5;
    //"Root directory is not supported";
    public static final int ERROR_ROOT_NOT_SUPPORTED = -6;
    //"Missing arguments for \"-definelabel\"";
    public static final int ERROR_MISSING_ARGUMENTS_DEFINELABEL = -7;
    //"Invalid label name \"" + name + "\"";
    public static final int ERROR_INVALID_LABEL_NAME = -8;
    //"Invalid label value \"" + value + "\"";
    public static final int ERROR_INVALID_LABEL_VALUE = -9;
    //"Invalid argument \"" + arg + "\"";
    public static final int ERROR_INVALID_ARGUMENT = -10;

    public ArgumentsParseException(int code,String message) {
        super(message);
        this.code = code;
    }

    ArgumentsParseException setArgs(String ...args) {
        if (args == null || args.length == 0){
            args = new String[0];
            return this;
        }
        List<String> argList = new ArrayList<>();
        for (String arg : args) {
            if (arg != null){
                argList.add(arg);
            }
        }
        this.args = argList.toArray(new String[0]);
        return this;
    }

    public int getCode() {
        return code;
    }

    public String[] getArgs() {
        return args == null ? new String[0] : args;
    }

}
